﻿using System;
using System.Collections.Generic;
using System.Text;
using Autofac;
using MgSoft.DependenceInjection.Autofac;
using MgSoft.Import.Model;

namespace MgSoft.Import.Exchange
{
    public abstract class ExchangeComponent : ImportComponent, IExchangeComponent
    {
        public abstract Type SchemeType { get; }
        public abstract ConfigUiType ConfigUiType { get; }

        public void CustomerConfigUi(object lifetimeScope, Action successCallTack, Action failCallBack)
        {
            throw new NotImplementedException();
        }

        public IExchangeScheme GetScheme(IContainer container)
        {
            return container.Resolve(SchemeType) as IExchangeScheme;
        }

        public override void Register(object builder)
        {
            ContainerBuilder containerBuilder = builder as ContainerBuilder;
            if (containerBuilder == null) throw new ArgumentException("builder need type is ContainerBuilder");

            containerBuilder.RegisterType(SchemeType);
            containerBuilder.RegisterType(this.GetType()).OnActivating(p => p.ReplaceInstance(this));
            RegisterAssemblyType.Register(this.GetType().Assembly, containerBuilder);

            /*registerExcelTaskManager(containerBuilder);

            OnRegister(containerBuilder);*/
        }
    }
}
